Skip to content

Fix deprecated APIs and correct Python version requirement#94

Merged
xuhdev merged 3 commits intoeditorconfig:masterfrom
latifbaihaki:fix/deprecated-apis-and-version-requirement
Dec 24, 2025
Merged

Fix deprecated APIs and correct Python version requirement#94
xuhdev merged 3 commits intoeditorconfig:masterfrom
latifbaihaki:fix/deprecated-apis-and-version-requirement

Conversation

@latifbaihaki
Copy link
Copy Markdown
Contributor

This PR fixes a critical issue where the package couldn't be installed due to an invalid Python version requirement (>=3.13.7) and modernizes the codebase by replacing deprecated APIs. The changes include updating the Python version requirement to >=3.9 to match the classifiers, replacing deprecated codecs.open with the built-in open() function, using context managers for proper file resource management, updating exception handling from IOError to OSError/FileNotFoundError for Python 3.9+ compatibility, and improving type hints by replacing StreamReaderWriter with TextIOBase. All changes are backward compatible and have been thoroughly tested.

…package can be installed on Python 3.9+ and improve code quality by replacing deprecated codecs.open with built-in open(), using context managers for proper file resource management, updating exception handling from IOError to OSError/FileNotFoundError for Python 3.9+ compatibility, and improving type hints by replacing StreamReaderWriter with TextIOBase from the io module.
pyproject.toml Outdated
description = "EditorConfig File Locator and Interpreter for Python"
readme = "README.rst"
requires-python = ">=3.13.7"
requires-python = ">=3.9"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.10 maybe? 3.9 has reached end of line.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, you can keep it this way, and I'll make another PR to correct the classifier altogether.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've adjusted the Python version to 3.10 and removed the redundant FileNotFoundError. Thanks for the review.

Copy link
Copy Markdown
Member

@xuhdev xuhdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I've posted two questions, otherwise the PR looks good.

except IOError:
with open(filename, encoding='utf-8', mode='r') as fp:
self._read(fp, filename)
except (OSError, FileNotFoundError):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OSError should have covered FileNotFoundError: https://docs.python.org/3/library/exceptions.html#OSError

This exception is raised when a system function returns a system-related error, including I/O failures such as “file not found” or “disk full” (not for illegal argument types or other incidental errors).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a critical installation issue caused by an unrealistic Python version requirement (>=3.13.7) and modernizes the codebase by replacing deprecated APIs. The Python version requirement is corrected to >=3.9, aligning with the package classifiers.

Key changes:

  • Updated Python version requirement from >=3.13.7 to >=3.9 in pyproject.toml
  • Replaced deprecated codecs.open() with built-in open() function
  • Implemented proper resource management using context managers
  • Updated exception handling from IOError to OSError/FileNotFoundError
  • Improved type hints by replacing StreamReaderWriter with TextIOBase

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pyproject.toml Corrects Python version requirement to >=3.9, matching existing classifiers
editorconfig/ini.py Modernizes file handling with context managers, updates deprecated imports and exception types, improves type hints

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

except IOError:
with open(filename, encoding='utf-8', mode='r') as fp:
self._read(fp, filename)
except (OSError, FileNotFoundError):
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileNotFoundError is a subclass of OSError since Python 3.3. Since this code requires Python 3.9+, catching OSError alone is sufficient and more idiomatic. The explicit FileNotFoundError in the exception tuple is redundant.

Suggested change
except (OSError, FileNotFoundError):
except OSError:

Copilot uses AI. Check for mistakes.
@editorconfig editorconfig deleted a comment from Copilot AI Dec 23, 2025
@latifbaihaki latifbaihaki requested a review from xuhdev December 23, 2025 02:26
@xuhdev xuhdev enabled auto-merge (squash) December 24, 2025 06:48
@xuhdev xuhdev merged commit 28f050f into editorconfig:master Dec 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants